package qotwReader;

import org.apache.commons.lang.StringEscapeUtils;

import qotwReader.question.QuestionData;

public class CmdOptions
{
    private static final String author = "b3ta.com";
    private static final String tag = "b3ta Question of the Week";
    
    final private QuestionData data;
    
    public CmdOptions(QuestionData data)
    {
        this.data = data;
    }
    
    public String getOptionsForConversion()
    {
        return getInputToEpubCmd() + " " + getMetadataOptions();
    }
    
    private String getInputToEpubCmd()
    {
        String cmd = "";
        
        cmd += optionToCommandLine("--output-profile", data.getReaderType().toString());
        cmd += optionToCommandLine("--no-default-epub-cover");
        cmd += optionToCommandLine("--no-svg-cover");
        cmd += optionToCommandLine("--max-levels", "1");
        cmd += optionToCommandLine("--max-toc-links", "0");
        
        return cmd;
    }
    
    private String getMetadataOptions()
    {
        String metadata = "";
        
        metadata += optionToCommandLine("--author-sort", CmdOptions.author);
        metadata += optionToCommandLine("--authors", CmdOptions.author);
        metadata += optionToCommandLine("--book-producer", CmdOptions.author);
        metadata += optionToCommandLine("--comments", data.getHtmlsafeComments());
        metadata += optionToCommandLine("--pubdate", data.getHtmlsafeDate());
        metadata += optionToCommandLine("--publisher", CmdOptions.author);
        metadata += optionToCommandLine("--timestamp", data.getHtmlsafeDate());
        metadata += optionToCommandLine("--title", data.getHtmlsafeTitle());
        metadata += optionToCommandLine("--title-sort", data.getHtmlsafeTitle());
        metadata += optionToCommandLine("--tags", CmdOptions.tag);
        
        return metadata;
    }
    
    private String optionToCommandLine(String option)
    {
        return " " + option + " ";
    }
    
    private String optionToCommandLine(String option, String arg)
    {
        return " " + option + " \"" + StringEscapeUtils.escapeHtml(arg) + "\" ";
    }
}
